home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / TimGA 1.2.1 / .cp / CFitness.cp < prev    next >
Encoding:
Text File  |  1997-07-16  |  2.7 KB  |  84 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    CFitness.cp            ©1995-97 Timo Eloranta        All rights reserved.
  3. // ===========================================================================
  4. //    This class is used for storing the fitness of a single graph drawing,
  5. //    as well as for comparing the quality of different drawings.
  6.  
  7. //  Most of the stuff is inlined and located in CFitness.h...
  8.  
  9. #include "CFitness.h"
  10. #include <PP_Constants.h>
  11.  
  12. // === Static Member Variables ===
  13.  
  14. SEvaluation* CFitness::sEvaluation = nil;
  15.  
  16. // ---------------------------------------------------------------------------
  17. //        • CFitness
  18. // ---------------------------------------------------------------------------
  19. //    Constructor.
  20.  
  21. CFitness::CFitness()
  22. {    
  23.     SetCrossings( 0L );
  24.     SetEdgeStuff( 0L );
  25.     SetMinDistance ( 0L );
  26. }
  27.  
  28. // ---------------------------------------------------------------------------
  29. //        • operator=
  30. // ---------------------------------------------------------------------------
  31.  
  32. CFitness & 
  33. CFitness::operator=( const CFitness & inFitness)
  34. {
  35.     mCrossings                = inFitness.mCrossings;
  36.     mEdgeDeviation            = inFitness.mEdgeDeviation;
  37.     mMinNodeDistance        = inFitness.mMinNodeDistance;
  38.     mMinDistSum                = inFitness.mMinDistSum;
  39.  
  40.     mSecondValue            = inFitness.mSecondValue;
  41.     
  42.     return *this;
  43. }
  44.  
  45. // ---------------------------------------------------------------------------
  46. //        • SetMinDistance
  47. //
  48. //          Called by:    CFitness::CFitness
  49. //                        CGraphDrawing::Evaluate
  50. //                        CGraphNodes::BruteForceClosestPairs
  51. // ---------------------------------------------------------------------------
  52. //    Stores the smallest distance between a pair of nodes (inMinDist)
  53. //    and the sum of minimum node-to-node distances (inMinDistSum). 
  54. //    Also calculates the fitness function value according to multipliers
  55. //    which can be set in the Evaluation dialog.
  56.  
  57. void 
  58. CFitness::SetMinDistance( Int32 inMinDist, Int32 inMinDistSum, 
  59.                             Int16 inNodes, Int16 inGridSize )
  60. {
  61.     // If the minimum distances have not been calculated (in order to save
  62.     // time...), this function is called with the inMinDist parameter set
  63.     // to 0 (which is not normally possible!). In this case we ignore the
  64.     // other parameters and set the mSecondValue to something *very* small...
  65.  
  66.     if ( inMinDist ) {
  67.     
  68.         mMinNodeDistance    = inMinDist;
  69.         mMinDistSum            = inMinDistSum;
  70.     
  71.         mSecondValue    =    
  72.             (  (sEvaluation -> multip1) * mMinDistSum) -
  73.             (  (sEvaluation -> multip2) * mEdgeDeviation) -
  74.             ( ((sEvaluation -> multip3) * mEdgeDeviation) / 
  75.               ((sEvaluation -> multip4) * mMinNodeDistance) ) +
  76.             ( (inNodes / (sEvaluation -> multip5) ) * 
  77.                mMinNodeDistance * mMinNodeDistance ) -
  78.             ( (sEvaluation -> multip6) * mCrossings * 
  79.                (inGridSize * inGridSize / (sEvaluation -> multip7) ) );
  80.  
  81.     } else 
  82.         mSecondValue        = min_Int32;
  83. }
  84.